package com.example.blog_system_ssm.component;

import lombok.Data;

import java.io.Serializable;

// 返回统一对象
@Data
public class AjaxResult implements Serializable {
    private Integer code;
    private String message;
    private Object data;


    // 返回成功数据
    public static AjaxResult success(Object data){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(200);
        ajaxResult.setMessage("");
        ajaxResult.setData(data);
        return ajaxResult;
    }

    public static AjaxResult success(Object data,String message){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(200);
        ajaxResult.setMessage(message);
        ajaxResult.setData(data);
        return ajaxResult;
    }

    // 返回失败数据
    public static AjaxResult fail(Integer code,String message){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(code);
        ajaxResult.setMessage(message);
        ajaxResult.setData("");
        return ajaxResult;
    }

    public static AjaxResult fail(Integer code,Object data,String message){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(code);
        ajaxResult.setMessage(message);
        ajaxResult.setData(data);
        return ajaxResult;
    }
}
